#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<conio.h>

#define g 0.5 //重力加速度
#define width 800
#define height 600
#define num_max 10 //烟花绽放后最多有10个矩形
#define PI 3.1415926 //圆周率
#define g_x 0.5
#define g_y 0.5

float rectangle_left;
float rectangle_top;

void ball_1(float x, float y, int radius, int num, float angle, int RADIUS)
{
	rectangle_left = x;
	rectangle_top = y;
	x = RADIUS / cos(angle) + x;
	y = y + RADIUS * sin(angle);
	fillcircle(x, y, radius);
	num = num + 1;
	if (num <= num_max)
	{
		x = rectangle_left;
		y = rectangle_top;
		radius = 2;
		angle = angle + PI / 5;
		ball_1(x, y, radius, num, angle, RADIUS);
	}
}

void ball_2(float x, float y, int radius, int num, float angle, int RADIUS)
{
	float rectangle_left;
	float rectangle_top;
	rectangle_left = x;
	rectangle_top = y;
	y = RADIUS / cos(angle) + y;
	x = x + RADIUS * sin(angle);
	fillcircle(x, y, radius);
	num = num + 1;
	if (num <= num_max)
	{
		x = rectangle_left;
		y = rectangle_top;
		radius = 2;
		angle = angle + PI / 5;
		ball_2(x, y, radius, num, angle, RADIUS);
	}
}
void show1()
{
	int rectangle_height = 10;//矩形的高
	int rectangle_width = 2;//矩形的宽
	float rectangle_left;
	float rectangle_top = height - rectangle_height;
	float rectangle_right;
	float rectangle_bottom;
	float rectangle_vy = 22;//定义矩形的初速度；
	float rectangle_vx = 0;
	float rectangle_v = 0;
	float h = rand() % 180;
	COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
	COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);

	while (1)
	{
		rectangle_left = 200;
		rectangle_top = rectangle_top - rectangle_vy;//根据公式更新矩形的左上纵坐标
		rectangle_right = rectangle_left + rectangle_width;
		rectangle_bottom = rectangle_top + rectangle_height;//根据公式更新矩形的右下纵坐标
		cleardevice();
		fillrectangle(rectangle_left, rectangle_top, rectangle_right, rectangle_bottom);
		rectangle_vy = rectangle_vy - g;//根据速度公式更新矩形的速度
		Sleep(10);
		if (rectangle_vy == 0)
		{
			break;
		}
	}
	cleardevice();

	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 8);
	setfillcolor(color1);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 8);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 9);
	setfillcolor(color2);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 9);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(80);
	cleardevice();
}
void show2()
{
	int rectangle_height = 10;//矩形的高
	int rectangle_width = 2;//矩形的宽
	float rectangle_left;
	float rectangle_top = height - rectangle_height;
	float rectangle_right;
	float rectangle_bottom;
	float rectangle_vy = 18;//定义矩形的初速度；
	float rectangle_vx = 0;
	float rectangle_v = 0;
	float h = rand() % 180;
	COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
	COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);

	while (1)
	{
		rectangle_left = 500;
		rectangle_top = rectangle_top - rectangle_vy;//根据公式更新矩形的左上纵坐标
		rectangle_right = rectangle_left + rectangle_width;
		rectangle_bottom = rectangle_top + rectangle_height;//根据公式更新矩形的右下纵坐标
		cleardevice();
		fillrectangle(rectangle_left, rectangle_top, rectangle_right, rectangle_bottom);
		rectangle_vy = rectangle_vy - g;//根据速度公式更新矩形的速度
		Sleep(10);
		if (rectangle_vy == 0)
		{
			break;
		}
	}
	cleardevice();

	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 8);
	setfillcolor(color2);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 8);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 9);
	setfillcolor(color1);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 9);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(80);
	cleardevice();
}

void show3()
{
	int rectangle_height = 10;//矩形的高
	int rectangle_width = 2;//矩形的宽
	float rectangle_left;
	float rectangle_top = height - rectangle_height;
	float rectangle_right;
	float rectangle_bottom;
	float rectangle_vy = 16;//定义矩形的初速度；
	float rectangle_vx = 0;
	float rectangle_v = 0;
	float h = rand() % 180;
	COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
	COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);

	while (1)
	{
		rectangle_left = 300;
		rectangle_top = rectangle_top - rectangle_vy;//根据公式更新矩形的左上纵坐标
		rectangle_right = rectangle_left + rectangle_width;
		rectangle_bottom = rectangle_top + rectangle_height;//根据公式更新矩形的右下纵坐标
		cleardevice();
		fillrectangle(rectangle_left, rectangle_top, rectangle_right, rectangle_bottom);
		rectangle_vy = rectangle_vy - g;//根据速度公式更新矩形的速度
		Sleep(10);
		if (rectangle_vy == 0)
		{
			break;
		}
	}
	cleardevice();

	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 8);
	setfillcolor(color1);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 8);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 9);
	setfillcolor(color2);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 9);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(80);
	cleardevice();
}
void show4()
{
	int rectangle_height = 10;//矩形的高
	int rectangle_width = 2;//矩形的宽
	float rectangle_left;
	float rectangle_top = height - rectangle_height;
	float rectangle_right;
	float rectangle_bottom;
	float rectangle_vy = 20;//定义矩形的初速度；
	float rectangle_vx = 0;
	float rectangle_v = 0;
	float h = rand() % 180;
	COLORREF color1 = HSVtoRGB(h, 0.9, 0.8);
	COLORREF color2 = HSVtoRGB(h + 180, 0.9, 0.8);

	while (1)
	{
		rectangle_left = 400;
		rectangle_top = rectangle_top - rectangle_vy;//根据公式更新矩形的左上纵坐标
		rectangle_right = rectangle_left + rectangle_width;
		rectangle_bottom = rectangle_top + rectangle_height;//根据公式更新矩形的右下纵坐标
		cleardevice();
		fillrectangle(rectangle_left, rectangle_top, rectangle_right, rectangle_bottom);
		rectangle_vy = rectangle_vy - g;//根据速度公式更新矩形的速度
		Sleep(10);
		if (rectangle_vy == 0)
		{
			break;
		}
	}
	cleardevice();

	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 8);
	setfillcolor(color2);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 8);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 9);
	setfillcolor(color1);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 9);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 10);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 11);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 12);
	Sleep(1);
	ball_2(rectangle_left + 20, rectangle_top, 1, 0, 0, 12);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 13);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 14);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 15);
	Sleep(20);
	cleardevice();
	ball_1(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(1);
	ball_2(rectangle_left, rectangle_top, 1, 0, 0, 20);
	Sleep(80);
	cleardevice();
}

int main()
{
	initgraph(width, height);//设置画布大小

	while (1)
	{
		show1();
		show2();
		show3();
		show4();
	}

	_getch();
	closegraph();
	return 0;
}
